package com.ruoyi.worker.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.worker.constant.Constant;
import com.ruoyi.worker.domain.Company;
import com.ruoyi.worker.domain.RzBlockWorker;
import com.ruoyi.worker.domain.TimeShift;
import com.ruoyi.worker.domain.WorkerInfos;
import com.ruoyi.worker.mapper.TermWorkerMapper;
import com.ruoyi.worker.mapper.WorkerInfoMapper;
import com.ruoyi.worker.service.WorkerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @ClassName WorkerinfoServiceImpl
 * @Description TODO
 * @Author zhanglei
 * Date 2021/8/24 14:33
 * @Version 1.0
 **/
@Service
public class WorkerInfoServiceImpl implements WorkerInfoService {

    @Autowired
    private WorkerInfoMapper workerInfoMapper;

    @Autowired
    private TermWorkerMapper termWorkerMapper;
    /**
     * @Description : 员工信息查询
     * @Author : leizhang
     * @Date 12:09 上午 2021/8/25
     * @param
     * @return java.util.List<com.ruoyi.worker.domain.WorkerInfos>
     **/
    @Override
    public List<WorkerInfos> getWorkerInfos(WorkerInfos workerInfos) {
        return workerInfoMapper.selectWorkerInfoList(workerInfos);
    }

    @Override
    public List<Company> selectCompanyInfos(Map<String, Object> requestParam) {
        return workerInfoMapper.selectCompanyInfos(requestParam);
    }

    @Override
    public List<TimeShift> selectTimeShiftInfos(Map<String, Object> requestParam) {
        return workerInfoMapper.selectTimeShiftInfos(requestParam);
    }

    @Override
    public int updateRoleStatus(Map<String, Object> requestParam) {
        return workerInfoMapper.updateRoleStatus(requestParam);

    }

    @Override
    public int updateWorkStatus(String orderCode,String status) {
       return workerInfoMapper.updateWorkStatus(orderCode,status);
    }

    @Override
    public String getImg(int workerId) {
       return workerInfoMapper.getImg(workerId);
    }

    @Override
    public List<WorkerInfos> listWorkerInfo(WorkerInfos workerInfos) {
        return workerInfoMapper.listWorkerInfo(workerInfos);
    }

    @Override
    public WorkerInfos getWorker(Long id) {
        return workerInfoMapper.getWorker(id);
    }

    @Override
    public int modifyWorkerInfo(WorkerInfos workerInfos) {
        return workerInfoMapper.modifyWorkerInfo(workerInfos);
    }

    @Override
    public int countWorkerInfoByIdCard(WorkerInfos workerInfos) {
        return workerInfoMapper.countWorkerInfoByIdCard(workerInfos);
    }

    @Override
    public int addBatchWorkerInfo(List<WorkerInfos> list) {
        return workerInfoMapper.addBatchWorkerInfo(list);
    }

    @Override
    public int delWorkerInfo(long id) {
        List<Map<String,Object>> list =workerInfoMapper.ListWorkerFileList(id);
        int flag =workerInfoMapper.delWorkerFile(id);
        if(flag >0 && list.size()>0){
//            for(Map<String,Object> map:list){
//                FileUtils.deleteFile("/images/"+map.get("filePath"));
//            }
            workerInfoMapper.delWorkerImg(id);
        }

        return workerInfoMapper.delWorkerInfo(id);
    }

    /**
     * 加入黑名单_临时工
     *
     * @param beau:黑名单对象
     * @return com.ruoyi.common.core.domain.AjaxResult
     * @author Hush.
     * @since 2021/12/15 17:53
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateWorkStatus(RzBlockWorker beau) {
        beau.setWorkerType(Constant.WORKER_TYPE_L);
        beau.setCreateTime(DateUtils.getNowDate());
        beau.setCreateBy(SecurityUtils.getUsername());
        termWorkerMapper.addBlackList(beau);
        return workerInfoMapper.updateWorkerStatus(beau.getWorkerId(), Constant.WORKER_STATUS_BLOCK_L);
    }
}